package com.sangmo.fts.process.inventory.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.Formula;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.basic.model.FileUpload;
import com.sangmo.fts.common.IConstants;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;

@Entity
@Table(name = "if_stock")
@DataView
@ExtView
@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
public class IfStock extends SoftDeleteEntity {

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long trainingId;

    @DataField(value = IConstants.DATA_TYPE.STRING_10,required = true, index = true, unique = true)
    private String code;

    @One(value = "waybill",target = IfWaybill.class, fieldset = {"id","code"},groups = {"IfStock.search", "IfStock.detail","IfStock.selection"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long waybillId;

    @One(value = "storageCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long storager;

    @DataField(required = true)
    private Date storageTime;

    @DataField(value = IConstants.DATA_TYPE.DECIMAL_POSITIVE_MONEY, required = true)
    private BigDecimal goodsTotalAmount;

    @DataField(value = IConstants.DATA_TYPE.DATE_BEGIN, required = true)
    private Date startTime;

    @DataField(value = IConstants.DATA_TYPE.DATE_END, required = true)
    private Date endTime;

    @One(value = "confirmDocument", target = FileUpload.class, fieldset = {"id","url","fileName"},groups = {"IfStock.search","IfStock.detail"})
    private Long confirmDoc;

    @DataField(value = IConstants.IF_STOCK_DATA_TYPE.STOCK_STATE, required = true, index = true)
    private String state = States.INBOUND;

    public Long getTrainingId() {
        return trainingId;
    }

    public void setTrainingId(Long trainingId) {
        this.trainingId = trainingId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Long getWaybillId() {
        return waybillId;
    }

    public void setWaybillId(Long waybillId) {
        this.waybillId = waybillId;
    }

    public Long getStorager() {
        return storager;
    }

    public void setStorager(Long storager) {
        this.storager = storager;
    }

    public Date getStorageTime() {
        return storageTime;
    }

    public void setStorageTime(Date storageTime) {
        this.storageTime = storageTime;
    }

    public BigDecimal getGoodsTotalAmount() {
        return goodsTotalAmount;
    }

    public void setGoodsTotalAmount(BigDecimal goodsTotalAmount) {
        this.goodsTotalAmount = goodsTotalAmount;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Long getConfirmDoc() {
        return confirmDoc;
    }

    public void setConfirmDoc(Long confirmDoc) {
        this.confirmDoc = confirmDoc;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public interface States {
        String INBOUND = "INBOUND"; //已入库
        String PENDING = "PENDING"; //待核定
        String CHECKED = "CHECKED"; //已核定
    }

}
